package operation;

import Book.Book;
import Book.Booklist;

import java.util.Scanner;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-05-23
 * Time:21:27
 */
public class DelOperation implements IOperation{

    @Override
    public void work(Booklist booklist) {
        System.out.println("删除图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入需要删除的图书名字:");
        String name = scanner.nextLine();
        int nowSize = booklist.getUsedSize();
        for (int i = 0; i < nowSize; i++) {
            if (name.equals(booklist.getBooks(i).getName())){
                for (int j = i; j > 0 ; j--) {
                    Book book = booklist.getBooks(j-1);
                    book=booklist.getBooks(j);
                }
                booklist.setUsedSize(nowSize-1);
                System.out.println("删除成功!");
                return;
            }

        }
        System.out.println("该图书已被删除！");
    }
}
